/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * <p>Project: jse2302 - MapDemo
 * <p>Powered by webrx On 2023-06-25 16:40:12
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class MapDemo {
    public static void main(String[] args) {
        //map集合是 key value键值对双列集合，key不允许重复，如果重复，就覆盖值
        Map<String, Integer> map = new HashMap<>();
        map.put("java", 200);
        map.put("php", 90);
        map.put("html", 90);
        map.put("mysql", 90);
        map.put("c", 230);
        map.put("java", 280);
        //map.clear();
        System.out.println(map.size());//3
        System.out.println(map);

        //判断
        System.out.println(map.containsKey("java"));
        System.out.println(map.containsValue(900));

        //获取
        System.out.println("-------------");
        System.out.println(map.get("java"));
        System.out.println(map.get("javascript"));
        Integer java = map.getOrDefault("javascript", 100);
        System.out.println(java);
        System.out.println("-------------");
        
        Set<Map.Entry<String, Integer>> entries = map.entrySet();
        for (Map.Entry<String, Integer> e : entries) {
            System.out.println(e);
        }

        //删除清空
        //map.clear();
        //Integer java1 = map.remove("java"); //出栈
        //map.remove("java"); //出栈
        map.remove("java", 6);
        System.out.println(map);

        Map<Integer, Integer> m = new HashMap<>(Map.of(1, 2, 2, 4, 3, 9, 4, 16));
        System.out.println(m.get(2));
        //m.replace(2, 40);
        m.put(2, 60);
        //m.replace(2, 40);
        System.out.println(m.get(2));
        System.out.println(m);


    }
}
